package com.shujia.mr.dianxin2;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.lib.input.FileSplit;

import java.io.IOException;

//part-r-00000
//00595A38A1F98846E4F788276F34173EC758BC20-8340104	22
//<"83401","$00595A38A1F98846E4F788276F34173EC758BC20-22">

//<"83401","$47BE1E866CFC071DB19D5E1C056BE28AE24C16E7-11">

//citys_id.txt
//83401,合肥市
//<"83401","#合肥市">

//<"83401",["$00595A38A1F98846E4F788276F34173EC758BC20-22","#合肥市","$47BE1E866CFC071DB19D5E1C056BE28AE24C16E7-11"]>

public class DianXinJoinCityMappr extends Mapper<LongWritable, Text, Text, Text> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, Text>.Context context) throws IOException, InterruptedException {
        FileSplit inputSplit = (FileSplit) context.getInputSplit();
        String fileName = inputSplit.getPath().getName();
        String line = value.toString();
        if (fileName.startsWith("part")) {
            String[] strings = line.split("\t");
            String[] strings1 = strings[0].split("-");
            String phoneNum = strings1[0];
            String city_id = strings1[1].substring(0, 5);
            String avg_time = strings[1];
            context.write(new Text(city_id), new Text("$" + phoneNum + "-" + avg_time));
        } else if (fileName.startsWith("city")) {
            String[] strings = line.split(",");
            String city_id = strings[0];
            String city_name = strings[1];
            context.write(new Text(city_id), new Text("#" + city_name));
        }
    }
}
